const a = async function (...args) {
  const [d, l] = args.slice(-2);
  const { memory, transfer } = d;
  const {
    dc: { http, message, reload, Confirm },
    xe: { get, set },
    h,
  } = l;
  const checkList = [
    ...get(memory, "checkListBonus", []),
    ...get(memory, "checkListBx", []),
  ];
  if (!checkList.length) return message.info("请至少选择一条数据");
  const noBankNoList = [];
  checkList.forEach((i) => {
    const { bankNo, programName } = i;
    if (!bankNo) {
      noBankNoList.push(`【${programName}】`);
    }
  });
  if (noBankNoList.length) {
    return message.info(
      `您所选择的摘要为${noBankNoList.join("，")}的数据无银联号信息，请检查`
    );
  }
  const ret = await new Promise((resolve) => {
    Confirm({
      iconType: "info",
      title: "线下支付",
      content: h("div", [
        h("span", "是否将"),
        h("br"),
        checkList.map((i) => {
          return [
            h("span", [
              h("span", `【${i.programName}-`),
              h("span", `${i.recNo}-`),
              h("span", `金额为`),
              h("span", { style: { color: "red" } }, `${i.money}`),
              h("span", `】，`),
            ]),
            h("br"),
          ];
        }),
        h("span", "的数据进行线下支付"),
      ]),
      onOk: async () => resolve(true),
      onCancle: async () => resolve(false),
      width: 720,
    });
  });
  if (!ret) return;
  set(memory, "saveBtnLoading", true);
  try {
    if (transfer.transferBatch) {
      checkList.forEach((i) => {
        i.status = 7;
      });
      const res = await http.post(
        {
          url: "/ypxy/transferBatch/submit",
          data: { list: checkList, submitName: "", status: 7 },
        },
        { isTransformResponse: false }
      );
      set(memory, "saveBtnLoading", false);
      if (res.code !== 200) {
        message.error(res.msg || res.message || "新增批量线下支付出错");
      } else {
        message.success("新增批量线下支付成功");
        reload({ from: "1790218686092136450" });
        reload({ from: "1790217412655304705" });
        set(memory, "checkListBonus", []);
        set(memory, "checkListBx", []);
      }
    } else {
      const errorList = [];
      function toUp(str) {
        let newStr = "";
        let arr = str.split("_");
        arr.forEach((item, index) => {
          if (index > 0) {
            return (newStr += item.replace(item[0], item[0].toUpperCase()));
          } else {
            return (newStr += item);
          }
        });
        return newStr;
      }
      for (const item of checkList) {
        const params = {};
        Object.keys(item).forEach((key) => {
          params[toUp(key)] = item[key];
        });
        const res = await http.post(
          {
            url: "/ypxy/transfer/submit",
            data: { ...params, id: undefined, status: 7 },
          },
          { isTransformResponse: false }
        );
        if (res.code !== 200) {
          errorList.push(params.programName);
        }
      }
      if (errorList.length) {
        message.error(`项目${errorList.join(",")}线下支付失败`);
      } else {
        message.success("提交线下支付成功");
      }
      set(memory, "saveBtnLoading", false);
      if (errorList.length !== checkList.length) {
        reload({ from: "1790218686092136450" });
        reload({ from: "1790217412655304705" });
        set(memory, "checkListBonus", []);
        set(memory, "checkListBx", []);
      }
    }
  } catch (error) {
    set(memory, "saveBtnLoading", false);
  }
};
